using System;
using IO = System.IO;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.Modeling;

namespace EastBancTech.DSL.FileSystemDefinition
{
    public partial class DirectoryModel
    {
        internal string GetShortNameValue()
        {
            if (String.IsNullOrEmpty(this.Name))
                return "";
            
            return Native.FileSystemInterop.GetShortFileName(this.Store, Name);
        }

        internal string GetPathValue()
        {
            if (String.IsNullOrEmpty(this.Name))
                return "";

            if (this.Parent == null)
                //if (String.IsNullOrEmpty(this.FileSystem.Path))
                    return this.Name;
                //else
                    //return IO.Path.Combine(this.FileSystem.Path, this.Name);
            else
                return IO.Path.Combine(this.Parent.Path, this.Name);
        }

        /// <summary>
        /// This is temporary property, until new release of DSL is shiped.
        /// There is a bug in current version of DSL, 
        /// "We use derived relationships to implement this type of functionality - unfortunately, 
        /// they don't really work in the shipping CTPs in the DslDesigner - they will however work correctly in the V1 code"
        /// <see cref="http://forums.microsoft.com/msdn/showpost.aspx?postid=619004&siteid=1"/>
        /// </summary>
        public virtual LinkedElementCollection<AssemblyFileModel> Assemblies
        {
            get
            {
                LinkedElementCollection<FileModel> files = this.Files;
                LinkedElementCollection<AssemblyFileModel> assemblies = new LinkedElementCollection<AssemblyFileModel>(files.SourceElement, files.SourceDomainRole.Id);

                foreach (FileModel fileModel in files)
                    if (fileModel.GetDomainClass().Id.Equals(AssemblyFileModel.DomainClassId))
                        assemblies.Add(fileModel as AssemblyFileModel);

                return assemblies;
            }
        }
    }
}
